package com.hkyl.hospital.web.controller;

import com.hkyl.hospital.domain.ResultVo;
import com.hkyl.hospital.entity.Hospitalized;
import com.hkyl.hospital.entity.PatientOperation;
import com.hkyl.hospital.mapper.HospitalizedMapper;
import com.hkyl.hospital.service.HospitalOperationService;
import com.hkyl.hospital.service.HospitalizedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author sjh
 * @date 2023/07/15 10:54:53
 */
@RestController
@RequestMapping("hospitalOperation")
public class HospitalOperationController {

    Logger logger = LoggerFactory.getLogger(HospitalOperationController.class);
    @Autowired
    private HospitalOperationService hospitalOperationService;
    @Autowired
    private HospitalizedMapper hospitalizedMapper;

    @PostMapping("selectAll")
    public ResultVo selectAll(){
        return ResultVo.success(hospitalOperationService.selectAll());
    }

    @PostMapping("selectByName")
    public ResultVo selectByName(@RequestBody Map map) {
        String patientCard = (String) map.get("patientCard");
        logger.info(patientCard);
        Hospitalized hospitalized = hospitalOperationService.selectByUID(patientCard);
        return ResultVo.success(hospitalized);
    }

/*    @PostMapping("selectOne")
    public ResultVo selectOne(@RequestBody Map map) {
        String patientname = (String) map.get("patientname");
        return ResultVo.success(hospitalOperationService.selectByName(patientname));
    }*/

    @PostMapping("getOperation")
    public ResultVo getOperation(@RequestBody Map map) {
        Integer patientId = (Integer) map.get("patientId");
        logger.info(String.valueOf(patientId)+"+++++++++++++++");
        Integer pageNumber = (Integer) map.get("pageNumber");
        Integer pageSize = (Integer) map.get("pageSize");
        List<PatientOperation> patientoperations = hospitalOperationService.patientoperations(pageNumber, pageSize, patientId);
        return ResultVo.success(patientoperations);
    }
}
